#include "devbsp.h"

#include <QDebug>

DevBSP::DevBSP()
{
    m_ledHall = 0;
    m_ledRoom = 0;
    m_ledKitc = 0;
    m_ledLave = 0;
    m_beep = 1;
    ledInit();
    beepInit();
    keyExit_init();
}

~DevBSP()
{
}

void DevBSP::ledInit(void)
{
    pinMode(LED_HALL, OUTPUT);
    pinMode(LED_KITC, OUTPUT);
    pinMode(LED_LAVE, OUTPUT);
    pinMode(LED_ROOM, OUTPUT);

    digitalWrite(LED_HALL, 0);
    digitalWrite(LED_KITC, 0);
    digitalWrite(LED_LAVE, 0);
    digitalWrite(LED_ROOM, 0);
}

void DevBSP::beepInit(void)
{
    pinMode(BEEP, OUTPUT);
}

void DevBSP::beepOn(void)
{
    digitalWrite(BEEP, BEEP_ON);
}

void DevBSP::beepOff(void)
{
    digitalWrite(BEEP, BEEP_OFF);
}

void DevBSP::beepTips(void)
{
    beepOn();
    delay(50);
    beepOff();
}

void DevBSP::KEY1_Interrupt(void)
{
    qDebug() << "Key1\n";
    beepTips();
}

void DevBSP::KEY2_Interrupt(void)
{
    qDebug() << "Key1\n";
    beepTips();
}

void DevBSP::KEY3_Interrupt(void)
{
    qDebug() << "Key1\n";
    beepTips();
}

void DevBSP::KEY4_Interrupt(void)
{
    qDebug() << "Key1\n";
    beepTips();
}

void DevBSP::keyExitInit(void)
{
    if(wiringPiISR(KEY1, INT_EDGE_FALLING, &KEY1_Interrupt) < 0)
    {
        printf("Unable to setup ISR\n");
    }

    if(wiringPiISR(KEY2, INT_EDGE_FALLING, &KEY2_Interrupt) < 0)
    {
        printf("Unable to setup ISR\n");
    }

    if(wiringPiISR(KEY3, INT_EDGE_FALLING, &KEY3_Interrupt) < 0)
    {
        printf("Unable to setup ISR\n");
    }

    if(wiringPiISR(KEY4, INT_EDGE_FALLING, &KEY4_Interrupt) < 0)
    {
        printf("Unable to setup ISR\n");
    }
}


